package JUC.wn_syn_vlo;

/*
   1
    class任位置 main独立启！

   2
    独立 ij 无所谓
    要是 全局变量 只能static （final不能++

 */
public class 交替打印_wait_notify {

    static String suo="11";

    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (suo) {
                    for (int i = 1; i <= 9; i += 2) {

                        System.out.println("-> A");

                        System.out.println("pt " + i);

                        suo.notifyAll();

                        try {
                            System.out.print("A -> suo ");
                            suo.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                    }
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (suo) {
                    for (int j = 2; j <= 10; j += 2) {

                        System.out.println("-> B");

                        System.out.println("pt " + j);

                        suo.notifyAll();

                        try {
                            System.out.print("B -> suo ");
                            suo.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                    }
                }
            }
        }).start();
    }
}
